//
//  XDAvenueOfStarsController.m
//  XDEducation
//
//  Created by Ethan on 2017/5/15.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDAvenueOfStarsController.h"
#import "XDAvenueOfStarsCell.h"
#import "XDAvenueOfStarsModel.h"
#import "XDConstantHeaderFile.h"
#define kCell @"cell"
#import "WebViewController.h"
@interface XDAvenueOfStarsController ()
@property (nonatomic,strong) NSMutableArray *dataSource;//数据源
@property (nonatomic,copy)NSString *rolecode;
@end

@implementation XDAvenueOfStarsController

- (NSMutableArray *)dataSource {
    
    if (_dataSource == nil) {
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        self.rolecode = [defaults objectForKey:@"rolecode"];
        if (0 == [self.rolecode integerValue]) {//超级管理员
            
        }else if (1 == [self.rolecode integerValue]){//管理员
            
        }else if (2 == [self.rolecode integerValue]){//任课老师
            
        }else if (3 == [self.rolecode integerValue]){//家长
            
            self.dataSource = [NSMutableArray arrayWithObjects:@"天下父母心",@"家有儿女",@"打开天窗",@"如何有效激励",@"幸福课程",@"中国家庭教育专栏",@"是真的吗?",@"快乐生活小常识",@"丽华来帮忙",@"务工城市竞争力分析",@"全国用工需求趋势概况",@"创业之窗",@"国家经济产业布局概况",@"各省教育政策总览",@"星星公益", nil];
            
        }else if (4 == [self.rolecode integerValue]){//孩子
             self.dataSource = [NSMutableArray arrayWithObjects:@"天下父母心",@"家有儿女",@"打开天窗",@"是真的吗?",@"快乐生活小常识",@"星星公益", nil];
        }
       
    }
    
    return _dataSource;
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = self.nameTitle;
    self.view.backgroundColor = [UIColor whiteColor];
    

    
   
     [self initNetworkingWithRefreshStatus:RefreshStatePullDown];
    [self setUpSuperViews];
    
}

#pragma mark ---网络请求
-(void)initNetworkingWithRefreshStatus:(RefreshState)status{
    
   
    NSString *url = BaseURL(@"user.do?action=countClicks");
    NSDictionary *dict = @{@"uid":@"285",@"funcCode":@"16"};
    [XDHttpTool get:url authCode:[AccountTool shareAccountTool].currentAccount.authCode params:dict success:^(id responseObj) {
        
    } failure:^(NSError *error) {
        
    }];
    
}


#pragma mark --- 子视图
- (void)setUpSuperViews{
    UIView *grayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight *11/1334)];
    grayView.backgroundColor =  UIColor(232, 232, 234);
    [self.view addSubview:grayView];
    
    self.tableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64);
    [self.tableView registerClass:[UITableViewCell  class] forCellReuseIdentifier:kCell];
    self.tableView.tableFooterView = [UIView new];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    
    
}


#pragma mark --- 代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.dataSource.count;
}


 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCell forIndexPath:indexPath];
     cell.textLabel.text = self.dataSource[indexPath.row];
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
     cell.selectionStyle = UITableViewCellSelectionStyleNone;

 
 return cell;
 }

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSString *nameTitle;
   
    if (0 == [self.rolecode integerValue]) {//超级管理员
        
   
    }else if (1 == [self.rolecode integerValue]){//管理员
        
    }else if (2 == [self.rolecode integerValue]){//任课老师
        
    }else if (3 == [self.rolecode integerValue]){//家长
        if (0 == indexPath.row) {
            nameTitle = @"天下父母心";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_TXFMX&pageNumber=1"];
            [self theURL:str title:nameTitle];
        }else if (1 == indexPath.row){
            nameTitle = @"家有儿女";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_DKTC_JYEN&pageNumber=1"];
            [self theURL:str title:nameTitle];
        }else if (2 == indexPath.row){
            nameTitle = @"打开天窗";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_DKTC&pageNumber=1"];
            [self theURL:str title:nameTitle];
        }else if (3 == indexPath.row){
            
            nameTitle = @"如何有效激励";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_DKTC_RHYXJL&pageNumber=1"];
            [self theURL:str title:nameTitle];
            
            
        }else if (4 == indexPath.row){
            nameTitle = @"幸福课程";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_XFKCZYJ&pageNumber=1"];
            [self theURL:str title:nameTitle];
            
        }else if (5 == indexPath.row){
            nameTitle = @"中国家庭教育专栏";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_ZGJTJYZL&pageNumber=1"];
            [self theURL:str title:nameTitle];
            
        }else if (6 == indexPath.row){
            nameTitle = @"是真的吗？";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_SZDM&pageNumber=1"];
            [self theURL:str title:nameTitle];
            
        }else if (7 == indexPath.row){
            nameTitle = @"快乐生活小常识";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_KLSHXCS&pageNumber=1"];
            [self theURL:str title:nameTitle];
            
        }else if (8 == indexPath.row){
            nameTitle = @"丽华来帮忙";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_LHLBM&pageNumber=1"];
            [self theURL:str title:nameTitle];
            
        }else if (9 == indexPath.row){
            nameTitle = @"务工城市竞争力分析";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_WGCSJZLFX&pageNumber=1"];
            [self theURL:str title:nameTitle];

            
        }else if (10 == indexPath.row){
            nameTitle = @"全国用工需求趋势概况";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_QGYGXQQSGK&pageNumber=1"];
            [self theURL:str title:nameTitle];
            
        }else if (11 == indexPath.row){
            nameTitle = @"创业之窗";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_CYZC&pageNumber=1"];
            [self theURL:str title:nameTitle];
            
        }else if (12 == indexPath.row){
            nameTitle = @"国家经济产业布局概况";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_GJJJCYBJGK&pageNumber=1"];
            [self theURL:str title:nameTitle];
            
        }else if (13 == indexPath.row){
            nameTitle = @"各省教育政策总览";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_GSJYZCZL&pageNumber=1"];
            [self theURL:str title:nameTitle];
            
        }else if (14 == indexPath.row){
            nameTitle = @"星星公益";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_XXGY&pageNumber=1"];
            [self theURL:str title:nameTitle];
        }
        
    }else if (4 == [self.rolecode integerValue]){//孩子

        if (0 == indexPath.row) {
            nameTitle = @"天下父母心";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_TXFMX&pageNumber=1"];
            [self theURL:str title:nameTitle];
        }else if (1 == indexPath.row){
            nameTitle = @"家有儿女";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_DKTC_JYEN&pageNumber=1"];
            [self theURL:str title:nameTitle];
        }else if (2 == indexPath.row){
            nameTitle = @"打开天窗";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_DKTC&pageNumber=1"];
            [self theURL:str title:nameTitle];
        }else if (3 == indexPath.row){
            nameTitle = @"是真的吗？";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_SZDM&pageNumber=1"];
            [self theURL:str title:nameTitle];
        }else if (4 == indexPath.row){
            nameTitle = @"快乐生活小常识";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_KLSHXCS&pageNumber=1"];
            [self theURL:str title:nameTitle];
        }else if (5 == indexPath.row){
            nameTitle = @"星星公益";
            NSString *str = [[NSString alloc] initWithFormat:@"%@",Base@"bbsws.do?action=showalltopic&forumcode=XXDD_XXSQ_XGDD_XXGY&pageNumber=1"];
            [self theURL:str title:nameTitle];
        }

    }
    
    
    
}

- (void)theURL:(NSString *)str title:(NSString *)title{
    
    WebViewController *web = [WebViewController new];
    
    web.str = str;
    web.nameTitle = title;
    [self.navigationController pushViewController:web animated:YES];
}


@end
